import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // 重置css

import Element from 'element-ui'
import './styles/element-variables.scss'
//import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖
// 根据自己的暴露出来的名字和文件地址引入
import resetMessage from './utils/message'
import VueQuillEditor from 'vue-quill-editor'

import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

Vue.use(VueQuillEditor)
// element注册之后挂载,刚才封装好的js
Vue.prototype.$messages = resetMessage;
// Vue.prototype.$nextTickReduceWay = function (idName1, idName2, idName3) {
//   this.$nextTick(() => {
//     var adddialogVisible = document.getElementById(idName1);
//     var drawerTitle = document.getElementById(idName2);
//     var prompt_explanation = document.getElementById(idName3);
//     if (adddialogVisible && prompt_explanation && drawerTitle) {
//       const result = adddialogVisible.offsetHeight -
//         (prompt_explanation.offsetHeight + drawerTitle.offsetHeight + 100) +
//         "px"
//       console.log(result);
//       return result;
//     }

//   });
// };

import '@/styles/index.scss' // 全局css

import App from './App'
import store from './store'
import router from './router'

import './iconSvg' // icon
import './permission' // 权限控制
import * as filters from './filters' // 全局筛选器
import Pagination from '@/components/Pagination'
import SingleUpload from '@/components/FileUpload'
import EditorText from "@/components/Editor";
import fileUp from '@/components/fileUp'
import empty from '@/components/empty'
Vue.component('empty', empty);
Vue.component('EditorText', EditorText);
Vue.component('Pagination', Pagination);
Vue.component('SingleUpload', SingleUpload);
Vue.component('fileUp', fileUp);
Vue.use(Element, {
  size: Cookies.get('size') || 'small' // 设置element-ui 默认 size
})
Vue.directive('hasPermi', {
  inserted(el, binding, vnode) {
    let arr = store.getters.roleRoutes
    const hasPermissions = arr.some(permission => {
      if (permission == binding.value) {
        return true
      }
    })
    if (!hasPermissions) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  },
  // 更新指令的值时重新应用样式  
  update(el, binding, vnode) {
    let arr = store.getters.roleRoutes
    const hasPermissions = arr.some(permission => {
      if (permission == binding.value) {
        return true
      }
    })
    if (!hasPermissions) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  }
});
import VueAMap from 'vue-amap'; //引入高德地图
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: '14efe7b9c0a51017c1ee7c641758ba69',
  plugin: [ // 这里根据自己项目按需引入插件
    'AMap.Autocomplete',
    'AMap.PlaceSearch',
    'AMap.Scale',
    'AMap.OverView',
    'AMap.ToolBar',
    'AMap.MapType',
    'AMap.PolyEditor',
    'AMap.CircleEditor',// 圆形编辑器插件
    "AMap.Geolocation", // 定位控件，用来获取和展示用户主机所在的经纬度位置
    "AMap.Geocoder", // 地理编码与逆地理编码服务，用于地址描述与坐标间的相互转换
    "AMap.CitySearch",
  ]
});
window._AMapSecurityConfig = {
  securityJsCode: '你的安全密钥',
}
// 解决高德地图刷新显示不出来
const amapKeys = Object.keys(localStorage).filter(key => key.match(/^_AMap_/))
amapKeys.forEach(key => { localStorage.removeItem(key) })

// 注册全局筛选器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
